package com.example.springbootdemo.异步注解失效测试.shedule;

import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * 一个定时任务一个异步任务
 */
@Service
@SpringBootTest
@RunWith(SpringRunner.class)
public class ScheduledFour {
    @Scheduled(cron = "0 50 * * * ? ")
    @Async
    public void test1() {
        for (int i = 0; i < 20; i++) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("ScheduleFour-----子线程1名："+Thread.currentThread().getName());
        }
    }
    @Scheduled(cron = "0 50 * * * ? ")
    @Async
    public void test2() {
        for (int i = 0; i < 20; i++) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("ScheduleFour-----子线程2名："+Thread.currentThread().getName());
        }
    }
}
